package com.bms.client.controller;
import com.bms.client.pojo.ChuFangGuanLiChanXun;
import com.bms.client.pojo.ChuFangGuanLiGenXing;
import com.bms.client.pojo.ChuFangGuanLiZhengJia;
import com.bms.client.service.impl.ChuFangGuanLiServiceImpl;
import com.bms.client.utils.RedisUtils;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * 出访管理(ChuFangGuanLi)表控制层
 *
 * @author makejava
 * @since 2021-03-15 19:47:25
 * @version 1.0
 */
@RestController
@RequestMapping("ChuFangGuanLi")
@Api(value = "出访管理(ChuFangGuanLi)管理",tags = "出访管理(ChuFangGuanLi)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class ChuFangGuanLiController {
    /**
     * 服务对象
     */
    @Resource
    private ChuFangGuanLiServiceImpl chuFangGuanLiServiceImpl;
    @Resource
    private RedisUtils redisUtils;

    /**
     * 通过主键查询单条数据
     * @return 单条数据
     */
    @RequestMapping(value = "chaXunFenYe", method = RequestMethod.POST)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "POST")
    public Map<String, Object> chaXunFenYe(@RequestBody @ApiParam(name = "chuFangGuanLiChanXun",value = "pojo模型",required = true) @Valid ChuFangGuanLiChanXun chuFangGuanLiChanXun) {
        Map<String, String> map=new HashMap<>();
        System.out.println(chuFangGuanLiChanXun.toString());
        map.put("chuFangShenQingRen","*"+chuFangGuanLiChanXun.getChuFangShenQingRen()+"*");
        map.put("chuFangRen","*"+chuFangGuanLiChanXun.getChuFangRenYuan()+"*");
        return redisUtils.redisPage(chuFangGuanLiChanXun.getPage(),"chuFangGuanLi",map);
    }
//    /**
//     * 查询所有数据
//     * @return 返回所有数据
//     */
//    @RequestMapping(value = "chaXunAll", method = RequestMethod.GET)
//    @ApiOperation(value = "查询所有数据接口",notes = "查询所有数据接口",httpMethod = "GET")
//    public Map<String, Object> chaXunAll() {
//        return this.chuFangGuanLiServiceImpl.chaXunAll();
//    }
    
    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "shanChuById", method = RequestMethod.POST)
    @ApiOperation(value = "根据一个主键删除一条出访记录的接口",notes = "根据一个主键删除一条**记录的接口",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> shanChuById(@RequestParam("id") String id) {
        return this.chuFangGuanLiServiceImpl.shanChuById(id);
    }
    
    /**
     * 通过主键更新单条数据
     *
     * @param chuFangGuanLiGenXing 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "gengXinById", method = RequestMethod.POST)
    @ApiOperation(value = "更新出访记录",notes = "更新出访记录接口",httpMethod = "POST")
    public Map<String, Object> gengXinById(@Valid @RequestBody @ApiParam(name = "chuFangGuanLiGenXing",value = "pojo模型",required = true) ChuFangGuanLiGenXing chuFangGuanLiGenXing) {
        return this.chuFangGuanLiServiceImpl.gengXinById(chuFangGuanLiGenXing);
    }

    /**
     * 通过主键更新单条数据
     *
     * @param id 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "huiGuiById", method = RequestMethod.POST)
    @ApiOperation(value = "回归",notes = "回归接口",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> huiGuiById(@RequestParam("id") int id) {
        return this.chuFangGuanLiServiceImpl.huiGuiById(id);
    }
    
    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param chuFangGuanLiZhengJia 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "xinZeng", method = RequestMethod.POST)
    @ApiOperation(value = "新增出访记录",notes = "新增出访记录的接口",httpMethod = "POST")
    public Map<String, Object> xinZeng(@Valid @RequestBody @ApiParam(name = "chuFangGuanLiZhengJia",value = "pojo模型",required = true) ChuFangGuanLiZhengJia chuFangGuanLiZhengJia) {
        return this.chuFangGuanLiServiceImpl.xinZeng(chuFangGuanLiZhengJia);
    }
}